using System;
using Csla;
using ENT.PM.Datos.MysqlHelper;
using System.Data;

namespace ENT.PM.Core.Lookup
{
    [Serializable]
    public class TipoTransaccionLookup : NameValueListBase<int, string>
    {
        #region Factory Methods

        private static TipoTransaccionLookup _list;

        public static TipoTransaccionLookup GetNameValueList()
        {
            if (_list == null)
                _list = DataPortal.Fetch<TipoTransaccionLookup>();
            return _list;
        }

        public static void InvalidateCache()
        {
            _list = null;
        }

        private TipoTransaccionLookup()
        { /* require use of factory methods */ }

        #endregion

        #region Data Access

        private void DataPortal_Fetch()
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;

            HelperMySql objhm = HelperMySql.ObtenerConexion("");
            MySql.Data.MySqlClient.MySqlParameter[] parametros = new MySql.Data.MySqlClient.MySqlParameter[1];
            parametros[0] = new MySql.Data.MySqlClient.MySqlParameter("CODIGO", "TIPOTRANSACCION");
            foreach (DataRow items in objhm.EjecutarStoreProcedure(parametros, "Listar_Catalogo_Codigo").Tables[0].Rows)
            {
                this.Add(new NameValueListBase<int, string>.NameValuePair(Convert.ToInt32(items[0]), items[2].ToString()));
            }


            IsReadOnly = true;
            RaiseListChangedEvents = true;
        }

        #endregion
    }
}
